﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using WZVTC.SoftDev.DDDFW.Domain.Core;

namespace WZVTC.SoftDev.DDDFW.EntityServices
{
    //出于线程安全的原因，对于EntitiesServicesFactory，要求使用它的方法必须构造一个新的Factory实例，在EntitiesServicesFactory内
    //每一个Services都是用同一个UnitOfWork。这样保证了线程安全。
    public class EntitiesServicesFactory:IDisposable
    {
        //public virtual EntitiesServicesFactory();
        
        public EntitiesServicesFactory(IUnitOfWork context)
        {
            _context = context;
        }
       public void Dispose()
      {
         Dispose(true);
         GC.SuppressFinalize(this);
      }  
     protected virtual void Dispose(bool disposing)
     {
        if (!m_disposed)
        {
            if (disposing)
            {             
            } 
            if(_context!=null)
               _context.Dispose();
            m_disposed = true;
        }
     }  
     ~EntitiesServicesFactory()
     {
        Dispose(false);
     }  
      protected  bool m_disposed;
      protected IUnitOfWork _context; // TODO: 初始化为适当的值
     
        
    }
}
